package com.backend.modules.task.convert;

import com.backend.modules.system.convert.UserConvert;
import com.backend.modules.task.entity.TaskSubmission;
import com.backend.modules.task.vo.TaskSubmissionDetailVO;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 任务提交详情转换器
 */
public class TaskSubmissionDetailConvert {
    
    /**
     * 将提交记录实体转换为详情VO
     */
    public static TaskSubmissionDetailVO convert(TaskSubmission entity) {
        if (entity == null) {
            return null;
        }
        
        TaskSubmissionDetailVO vo = new TaskSubmissionDetailVO();
        vo.setId(entity.getId());
        vo.setStudent(UserConvert.convert(entity.getStudent()));
        vo.setComment(entity.getComment());
        vo.setSubmitTime(entity.getSubmitTime());
        vo.setIsLate(entity.getSubmitTime().isAfter(entity.getTask().getDeadline()));
        
        return vo;
    }
    
    /**
     * 将提交记录实体列表转换为详情VO列表
     */
    public static List<TaskSubmissionDetailVO> convertList(List<TaskSubmission> list) {
        return list.stream()
                .map(TaskSubmissionDetailConvert::convert)
                .collect(Collectors.toList());
    }
}